/**
 * Created by zzw on 2016/5/17.
 * 登陆
 */
$(function(){
    //密码的显示与隐藏
    $('#pwd').togglePassword({
        el: '#togglePassword'
    });
    //禁止密码复制粘贴
    $("#pwd").bind("cut copy paste", function(e){
        e.preventDefault();
    });
    $("#login").click(function () {
        var reg = /^1[3|4|5|8|7][0-9]\d{4,8}$/;
        var reg1 = /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}\.[a-zA-Z0-9]{1,5}/;
        var reg2 = /^[^ ]$/;
        var userName = $("#tel_email").val().trim();
        var pwd = $("#pwd").val().trim();
        if (userName == "" || userName == null) {
            alert("用户名不能为空！");
            return false;
        }
        if (pwd == "" || pwd == null) {
            alert("密码不能为空！");
            return false;
        }
        if(userName.indexOf("@")<0){
            if(!reg.test(userName)){
                alert("请输入正确的手机号或邮箱地址");
                return false;
            }
        }else{
            if(!reg1.test(userName)){
                alert("请输入正确的手机号或邮箱地址");
                return false;
            }
        }
        if(reg2.test(pwd)){
            alert("密码不能包含空格！");
            return false;
        }
        var param = JSON.stringify({"userName": userName, "pwd": pwd});
        $.fn.serviceInvoke(serviceAddress.Address, 'agent_app_login', 'login.action', param, function (result) {
            if (result.msg == "success") {
                //alert("登录成功！");
                 location.href = "layout/main.html";
                 window.localStorage.token = result.entity;
            } else {
                alert("用户名或密码错误");
                $("#pwd").val("");
            }
        });
    });
});
